package book;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:张熳
 * Date:2025-09-05
 * Time:14:30
 */

/**
 * 在书类中，将图书的信息（名字、作者等）封装起来，使用private修饰符，然后使用get/set公共方法对这些信息进行访问
 * 创建构造方法对成员变量进行初始化，注意，图书信息中的判断书是否被借出的isborrowed成员变量不需要初始化，因为boolean类型的变量未初始化时
 * 默认的初始值时false，正好表示未被借出，如果后续被借出了，使用公共方法将其改为true
 * 最后是重写一下toString方法，这样在打印信息时，直接使用对象引用打印也可以输出对象的信息，而不是输出对象的地址
 */

public class Book {
    private String name;
    private String author;
    private int price;
    private String type;
    private boolean isborrowed;

    public Book(String name, String author, int price, String type) {
        this.name = name;
        this.author = author;
        this.price = price;
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public boolean isIsborrowed() {
        return isborrowed;
    }

    public void setIsborrowed(boolean isborrowed) {
        this.isborrowed = isborrowed;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", type='" + type + '\'' +
                ((isborrowed == true) ? " 已借出" : " 未借出")+
                //", isborrowed=" + isborrowed +
                '}';
    }
}
